using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Threading;
using System.Globalization;

public partial class controls_usrOtherLink : System.Web.UI.UserControl
{
    string selectedLanguage;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[CE.Global.General.UserId] != null && Session[CE.Global.General.UserTypeId] != null)
        {
            if (Session[CE.Global.General.UserTypeId].ToString() == "300")
            {
                //HtmlGenericControl _br = new HtmlGenericControl("<br/>");
                //divSocialBar.Controls.AddAt(0, _br);
                divSocialBar.Visible = true;
                liFaceBook.Visible = false;
                liTwitter.Visible = false;
            }
            else if (Session[CE.Global.General.UserTypeId].ToString() == "400")
            {
                //HtmlGenericControl _br = new HtmlGenericControl("<br/>");
                //divSocialBar.Controls.AddAt(0, _br);
                divSocialBar.Visible = true;
                liFaceBook.Visible = false;
                liTwitter.Visible = false;
            }
            else
            {
                divSocialBar.Visible = false;
                liFaceBook.Visible = false;
                liTwitter.Visible = false;
            }
        }
        else
        {
            divSocialBar.Visible = true;
            liFaceBook.Visible = false;
            liTwitter.Visible = false;
        }


        btnLanguage.OnClientClick = "javascript:return confirm('" + Resources.CarInsurance.LanguageChangeMessage + "');";
        //For test language

        selectedLanguage = string.Empty;
    }
    protected void btnLanguage_Click(object sender, EventArgs e)
    {
        selectedLanguage = string.Empty;

        if (lblLanguage.Text != string.Empty)
        {
            Session["Language"] = lblLanguage.Text;
        }

        if (Session["Language"] != null)
        {
            selectedLanguage = Session["Language"].ToString();
        }
        else
        {
            selectedLanguage = "th-TH";
            Session["Language"] = selectedLanguage;
        }

        if (selectedLanguage == "th-TH")
        {
            Session["Language"] = "en-US";
        }
        else
        {
            Session["Language"] = "th-TH";
        }

        lblLanguage.Text = selectedLanguage;

        if (selectedLanguage == "en-US")
        {
            Response.Redirect(Request.UrlReferrer.AbsoluteUri.Replace("/en", ""));
        }
        else
        {
            string[] _arrList = Request.UrlReferrer.AbsoluteUri.Split('/');
            string _redirectUrl = "";
            _arrList[3] = "en/" + _arrList[3];
            for (int i = 0; i < _arrList.Length; i++)
            {

                if (i != _arrList.Length - 1)
                {
                    _redirectUrl += _arrList[i].ToString() + "/";
                }
                else
                {
                    _redirectUrl += _arrList[i].ToString();
                }

            }
            if (_arrList.Length == 4 && _redirectUrl.EndsWith("/"))
            {
                _redirectUrl += "home.aspx";
            }
            Response.Redirect(_redirectUrl);
        }
    }
}
